#pragma once
#ifndef __FIRST_WORD_H__
#define __FIRST_WORD_H__
// First集合类
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include "../lib/Word.h"
#include "../lib/Syntax.h"
using std::set;
using std::map;
using std::string;
using std::vector;

namespace compile
{
	class FirstWord
	{
	public:
		FirstWord();
		FirstWord(Syntax* syntax);
		void printFirst() const;
		~FirstWord();
		map<string, set<string>>getFirst() const;
	private:
		map<string, set<string>>first;


		void calculateFirst(vector<Word>word_vector);
		void calculateFirst(set<string> *insert_set,
			char count_key,
			vector<Word>*word_vector) const; // 递归计算First
		bool checkEnd(string key, set<string>*checked_set) const;
		void checkEnd(string key, set<string>* checked_set, bool* flag) const;
		static bool ifEndSign(char sign);
		void insertSet(string key, set<string>*insert_set);
		static string polyfillChar(char new_char);
	};
}
#endif
